<?php
if (!defined('WEB_ROOT')) {
	exit;
}

// make sure matg exists
if (isset($_GET['id']) && $_GET['id'] > 0) {
	$id = (int)$_GET['id'];
} else {
	// redirect to index.php 
	header('Location: index.php');
}
if (isset($_GET['nganh_id']) && $_GET['nganh_id'] > 0) {
	$nganh_id = (int)$_GET['nganh_id'];
}
// Lấy thông tin giáo trình - tài liệu
$sql = "SELECT sch.id, masach, tensach,  namxb, nhaxb, hinhanh_thumb, sotrang, nganh_id, tennganh, soluong, solantaiban, kichthuoc, trongluong, hinhanh
        FROM sach sch left join nganh ng on sch.nganh_id = ng.id
		WHERE sch.id = $id
		ORDER BY sch.id desc";
		
	$result = mysql_query($sql) or die('Không lấy được thông tin giáo trình - tài liệu. ' . mysql_error());
	$row    = mysql_fetch_assoc($result);
	extract($row);
	if ($hinhanh) {
		$hinhanh = WEB_ROOT . 'images/Book/' . $hinhanh;
	} else {
		$hinhanh = WEB_ROOT . 'images/no-image-large.png';
	}
	$sql = "SELECT id, tennganh
				FROM nganh
				ORDER BY id";
		$result = dbQuery($sql) or die('Không lấy được thông tin ngành. ' . mysql_error());
		
		$groups = array();
		$list = '';
		while($row = dbFetchArray($result)) {
			list($id_nganh, $name) = $row;
			$list .= "<option value=\"$id_nganh\"";
				if ($id_nganh == $nganh_id) {
					$list.= " selected";
				}
				$list .= ">$name</option>\r\n";
		}	
?> 
<div class="onecolumn">
				<div class="header">
					<span>Sửa thông tin giáo trình - tài liệu</span>
				</div>
				<br class="clear"/>
				<div class="content">
					<form action="processBook.php?action=modifyBook&id=<?php echo $id; ?>&nganh_id=<?php echo nganh_id; ?>" method="post" enctype="multipart/form-data" name="frmAddBook" id="frmAddBook">
					 <!--<p align="center" class="formTitle">Sửa thông tin tác giả</p>-->
					 
					<table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
					  <tr> 
						   <td width="300" class="label">Mã giáo trình - tài liệu</td>
						   <td colspan="5" class="content"> <input name="txtMasach" type="text" class="box" id="txtMasach" readonly="true" style="background-color:#DADADA" value="<?php echo $masach; ?>" size="20" maxlength="20"></td>
					  </tr>
					  <tr> 
						   <td width="300" class="label">Tên giáo trình - tài liệu</td>
						   <td colspan="5" class="content"> <input name="txtTensach" type="text" class="box" id="txtTensach" value="<?php echo $tensach; ?>" size="50" maxlength="50"></td>
					  </tr>
					  <tr> 
							   
						   <td width="300" class="label">Năm xuất bản</td>
						  <td width="221" class="content"> <input name="txtNamxb" type="text" id="txtNamxb" value="<?php echo $namxb; ?>" size="20" maxlength="20" class="box" /></td>
						   <td width="153" class="label"> Nhà xuất bản</td>
						  <td class="content" colspan="5"><input name="txtNhaxb" type="text" id="txtNhaxb" value="<?php echo $nhaxb; ?>" size="20" maxlength="20" class="box" /></td>
					  </tr>
					  <tr> 
						   <td width="300" class="label">Hình ảnh</td>
							 <td class="content" colspan="5"> <input name="fleImage" type="file" id="fleImage" class="box">
					<?php
						if ($hinhanh_thumb != '') {
					?>
						<br>
						<img src="<?php echo WEB_ROOT . BOOK_IMAGE_DIR . $hinhanh_thumb; ?>"> &nbsp;&nbsp;<a href="javascript:deleteImage(<?php echo $id; ?>);">Delete 
						Image</a> 
						<?php
						}
					?>    
						</td>
					  </tr>
					  <tr> 
						   <td width="300" class="label">Số trang</td>
						   <td class="content"><input name="txtSotrang" type="text" id="txtSotrang" value="<?php echo $sotrang; ?>" size="20" maxlength="20" class="box"> </td>
						   <td class="label">Kích thước</td>
						  <td width="159" class="content"><input name="txtKichthuoc" type="text" id="txtKichthuoc" value="<?php echo $kichthuoc; ?>" size="12" maxlength="12" class="box" /></td>
							<td width="218" class="label">Trọng lượng</td>
						  <td width="182" class="content"><input name="txtTrongluong" type="text" id="txtTrongluong" value="<?php echo $trongluong; ?>" size="7" maxlength="7" class="box" /> (gram)</td>
					  </tr>
					  <tr> 
						   <td width="300" class="label">Số lượng</td>
						   <td class="content"><input name="txtSoluong" type="text" id="txtSoluong" value="<?php echo $soluong; ?>" size="20" maxlength="20" class="box"> </td>
						   <td class="label">Số lần tái bản </span></td>
						   <td class="content" colspan="3"><input name="txtSolantaiban" type="text" id="txtSolantaiban" value="<?php echo $solantaiban; ?>" size="12" maxlength="12" class="box" /></td>
					  </tr>
					  
					  <tr> 
						   <td width="300" class="label">Ngành</td>
						   <td class="content" colspan="5"> <select name="cboBranch" id="cboBranch" class="box">
							<option value="" selected>-- Chọn ngành --</option>
								<?php
									echo $list;
								?>	 
							</select></td>
					  </tr>
					   </table>
					 <p align="center"> 
					  <input name="btnModifyBook" type="button" id="btnModifyBook" value="Lưu thay đổi" onClick="checkAddBookForm();" class="box">
					  &nbsp;&nbsp;<input name="btnCancel" type="button" id="btnCancel" value="  Hủy  " onClick="window.location.href='index.php';" class="box">  
					 </p>
					</form>
</div>
</div>